package com.test.demo.feign.fallback;

import com.test.demo.commons.ResponseResult;
import com.test.demo.commons.utils.MapperUtils;
import com.test.demo.domain.UmsAdmin;
import com.test.demo.dto.UmsAdminDto;
import com.test.demo.dto.params.IconParam;
import com.test.demo.dto.params.PasswordParam;
import com.test.demo.dto.params.ProfileParam;
import com.test.demo.feign.ProfileFeign;
import com.test.demo.service.UmsAdminService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 个人信息熔断
 *
 * @author 远 chards_
 * @date: 2020-02-20 15:25
 */
@Component
public  class ProfileFeignFallback implements ProfileFeign {

    public static final String BREAKING_MESSAGE = "请求失败了，请检查您的网络";

    @Resource
    private UmsAdminService umsAdminService;
    @Override
    public String info(String username) {

        UmsAdmin umsAdmin=umsAdminService.get(username);
        UmsAdminDto dto =new UmsAdminDto();
        BeanUtils.copyProperties(umsAdmin,dto);

            try {
                return MapperUtils.obj2json(new ResponseResult<UmsAdminDto>(ResponseResult.CodeStatus.BREAKING,BREAKING_MESSAGE,dto));
            } catch (Exception e) {
                e.printStackTrace();
            }

            return  null;
    }

    @Override
    public String update(ProfileParam profileParam) {
        try {
            return MapperUtils.obj2json(new ResponseResult<>(ResponseResult.CodeStatus.BREAKING,BREAKING_MESSAGE));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  null;
    }

    @Override
    public String modifyPassword(PasswordParam passwordParam) {
        try {
            return MapperUtils.obj2json(new ResponseResult<>(ResponseResult.CodeStatus.BREAKING,BREAKING_MESSAGE));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  null;
    }

    @Override
    public String modifyIcon(IconParam iconParam) {
        try {
            return MapperUtils.obj2json(new ResponseResult<>(ResponseResult.CodeStatus.BREAKING,BREAKING_MESSAGE));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  null;
    }
}
